﻿/* Mos
 Leafre : Leafre (240000000)
 
 Refining NPC: 
 * Level 110 weapons - Stimulator allowed
 */

        var status = 0;
var selectedType = -1;
var selectedItem = -1;
var stimulator = false;
var bustedDagger = false;
var item;
var mats;
var matQty;
var cost;
var stimID;
var 风暴套装四维随机1 = Math.floor(Math.random() * 7);
var 风暴套装四维随机2 = Math.floor(Math.random() * 7);
var 风暴套装四维随机3 = Math.floor(Math.random() * 7);
var 风暴套装四维随机4 = Math.floor(Math.random() * 7);
var 风暴套装攻击力随机 = Math.floor(Math.random() * 120);
var 风暴套装魔攻随机 = Math.floor(Math.random() * 120);
function start() {
    status = -2;
    action(1, 0, 0);
	if(风暴套装四维随机1 <3)
	{
		风暴套装四维随机1 = 3;
	}
	if(风暴套装四维随机2 <3)
	{
		风暴套装四维随机2 = 3;
	}
	if(风暴套装四维随机3 <3)
	{
		风暴套装四维随机3 = 3;
	}
	if(风暴套装四维随机4 <3)
	{
		风暴套装四维随机5 = 3;
	}
	if(风暴套装攻击力随机 <100)
	{
		风暴套装攻击力随机 = 100;
	}
	if(风暴套装魔攻随机 <100)
	{
		风暴套装魔攻随机 = 100;
	}
}

function action(mode, type, selection) {
    if (mode == 1) {
        status++;
    } else {
        cm.dispose();
        return;
    }
    if (status == -1) {
        cm.sendSimple("你好，我可以帮你制作武器和护甲，你想做打造点什么？\r\n#L0# #b制作武器\r\n#L100# #b制作护甲#l");
    } else if (status == 0) {
        if (selection == 0) {
            if (cm.haveItem(4001079)) {
                bustedDagger = true;
                cm.sendNext("這是什麼？在破獲匕首你似乎老了，我需要 #i" + 4011001 + "# 和 #i" + 4011002 + "#.");
            } else {
                var selStr = "行，你想做哪个系列的装备？#b";
                var options = new Array("材料怎么获得？", "[Lv100] 风暴套装 #k[四维3-7/双攻100-120]" /* "做一個弓箭手武器", "做一個法師武器", "做一個盜賊武器", "做一個海盜武器",
                        "做一個劍士武器使用催化劑", "做一個弓箭手武器使用催化劑", "做一個法師武器使用催化劑", "做一個盜賊武器使用催化劑", "做一個海盜武器使用催化劑" */);
                for (var i = 0; i < options.length; i++) {
                    selStr += "\r\n#L" + i + "# " + options[i] + "#l";
                }
                cm.sendSimple(selStr);
            }
        } else {
            cm.sendYesNo("太好了！我會告訴你我的能力的。大家都知道，這取決於耐久性的物品的等級和數量的物品的丟失，所以服務費各不相同？您想立即修復你的裝備？");
            status = 99;
        }

    } else if (status == 1) {
        if (bustedDagger) {
            if (cm.haveItem(4011001) && cm.haveItem(4011002) && cm.haveItem(4001079)) {
                cm.gainItem(4011001, -1);
                cm.gainItem(4011002, -1);
                cm.gainItem(4001079, -1);
                cm.gainItem(4001078, 1);
            } else {
                cm.sendOk("你沒有足夠的材料。");
            }
            cm.dispose();
        } else {
            selectedType = selection;
            if (selectedType > 5) {
                stimulator = true;
                selectedType -= 5;
            } else
                stimulator = false;
            if (selectedType == 0) { //What's a stim?
                cm.sendNext("#b制作卷轴：#k通过日常打野击杀小型BOSS获得\r\n#b装备结晶：#k通过分解鉴定后的装备获得\r\n#b各类矿石：#k通过击杀怪物获得母矿，然后在制作大厅矿石精炼大师制作")
                cm.dispose();
            } else if (selectedType == 1) { //warrior weapon
                var selStr = "明智的选择，那么你想做哪一个装备？#b";
                var weapon = new Array("风暴战剑(单手剑)#k - 等級. 100#b", "风暴斧(单手斧)#k - 等級. 100#b", "风暴金色锤(单手钝器)#k - 等級. 100#b"
				, "风暴龙牙破(短刀)#k - 等級. 100#b", "风暴双翼短杖(短杖)#k - 等級. 100#b", "风暴治愈长杖(长杖)#k - 等級. 100#b",
                        "风暴巨剑(双手剑)#k - 等級. 100#b", "风暴碟翼斧(双手斧)#k - 等級. 100#b", "风暴枫叶锤(双手钝器)#k - 等級. 100#b",
						"风暴枪(枪)#k - 等級. 100#b", "风暴半月矛(矛)#k - 等級. 100#b", "风暴弓(弓)#k - 等級. 100#b"
						, "风暴岩石(驽)#k - 等級. 100#b", "风暴正义(拳套)#k - 等級. 100#b", "风暴血色拳爪(指节)#k - 等級. 100#b");
                for (var i = 0; i < weapon.length; i++) {
                    selStr += "\r\n#L" + i + "# " + weapon[i] + "#l";
                }
                cm.sendSimple(selStr);
            } else if (selectedType == 2) { //bowman weapon
                var selStr = "明智的选择，那么你想做哪一个装备？#b";
                var weapon = new Array("龍形之弓#k - 等級. 110 弓#b", "飛龍弩#k - 等級. 110 弩#b");
                for (var i = 0; i < weapon.length; i++) {
                    selStr += "\r\n#L" + i + "# " + weapon[i] + "#l";
                }
                cm.sendSimple(selStr);
            } else if (selectedType == 3) { //magician weapon
                var selStr = "明智的选择，那么你想做哪一个装备？#b";
                var weapon = new Array("聖龍短杖#k - 等級. 108 短杖#b", "龍骨長杖#k - 等級. 110 長杖#b");
                for (var i = 0; i < weapon.length; i++) {
                    selStr += "\r\n#L" + i + "# " + weapon[i] + "#l";
                }
                cm.sendSimple(selStr);
            } else if (selectedType == 4) { //thief weapon
                var selStr = "明智的选择，那么你想做哪一个装备？#b";
                var weapon = new Array("阿拉伯彎刀#k - 等級. 110 力量短刀#b", "烈風短刃#k - 等級. 110 幸運短刀#b", "綠色龍牙拳刃#k - 等級. 110 拳套#b");
                for (var i = 0; i < weapon.length; i++) {
                    selStr += "\r\n#L" + i + "# " + weapon[i] + "#l";
                }
                cm.sendSimple(selStr);
            } else if (selectedType == 5) { //pirate weapon
                var selStr = "明智的选择，那么你想做哪一个装备？#b";
                var weapon = new Array("龍王之爪#k - 等級. 110 指虎#b", "聖龍金槍#k - 等級. 110 槍#b");
                for (var i = 0; i < weapon.length; i++) {
                    selStr += "\r\n#L" + i + "# " + weapon[i] + "#l";
                }
                cm.sendSimple(selStr);
            }
        }
    } else if (status == 2) {
        selectedItem = selection;
        if (selectedType == 1) { //warrior weapon
            var itemSet = new Array(1302249, 1312136, 1322182, 1332207, 1372162, 1382193, 1402174, 1412123,1422125,1432151,1442203,1452190,1462178,1472198,1482152);
            var matSet = new Array(
			new Array(4131000, 4011001, 4011004, 4260000,4260001), //1302249风暴战剑(单手剑)
			new Array(4131001, 4011001, 4011004, 4260000,4260001), //1312136风暴斧(单手斧)
			new Array(4131002, 4011001, 4011002, 4260000,4260001), //1322182风暴金色锤(单手钝器)
			new Array(4131012, 4011001, 4011003, 4260000,4260001),//1332207风暴龙牙破(短刀)
            new Array(4131008, 4011001, 4011005, 4260000,4260001), //1372162风暴双翼短杖(短杖)
			new Array(4131009, 4011001, 4011005, 4260000,4260001), //1382193风暴治愈长杖(长杖)
			new Array(4131003, 4011001, 4011006, 4260000,4260001), //1402174风暴巨剑(双手剑)
			new Array(4131004, 4011001, 4011005, 4260000,4260001),//1412123风暴碟翼斧(双手斧)
			new Array(4131004, 4011001, 4011002, 4260000,4260001),//1422125风暴枫叶锤(双手钝器)
			new Array(4131004, 4011001, 4011001, 4260000,4260001),//1432151风暴枪(枪)
			new Array(4131004, 4011001, 4011005, 4260000,4260001),//1442203风暴半月矛(矛)
			new Array(4131004, 4011001, 4011004, 4260000,4260001),//1452190风暴弓(弓)
			new Array(4131004, 4011001, 4011003, 4260000,4260001),//1462178风暴岩石(驽)
			new Array(4131004, 4011001, 4011002, 4260000,4260001),//1472198风暴正义(拳套)
			new Array(4131004, 4011001, 4011008, 4260000,4260001));//1482152风暴血色拳爪(指节)
            var matQtySet = new Array(
			new Array(1, 2, 1, 12,3), 
			new Array(1, 2, 1, 12,3), 
			new Array(1, 2, 1, 12,3), 
			new Array(1, 2, 1, 12,3), 
			new Array(1, 2, 1, 12,3), 
			new Array(1, 2, 1, 12,3), 
			new Array(1, 2, 1, 12,3), 
			new Array(1, 2, 1, 12,3),
			new Array(1, 2, 1, 12,3),
			new Array(1, 2, 1, 12,3),
			new Array(1, 2, 1, 12,3),
			new Array(1, 2, 1, 12,3),
			new Array(1, 2, 1, 12,3),
			new Array(1, 2, 1, 12,3),
			new Array(1, 2, 1, 12,3));
            var costSet = new Array(220000, 220000, 220000, 220000, 220000, 220000, 220000, 220000, 220000, 220000, 220000, 220000, 220000, 220000, 220000);
            item = itemSet[selectedItem];
            mats = matSet[selectedItem];
            matQty = matQtySet[selectedItem];
            cost = costSet[selectedItem];
        } else if (selectedType == 2) { //bowman weapon
            var itemSet = new Array(1452044, 1462039);
            var matSet = new Array(new Array(1452019, 4000244, 4000245, 4005000, 4005002), new Array(1462015, 4000244, 4000245, 4005000, 4005002));
            var matQtySet = new Array(new Array(1, 20, 25, 3, 5), new Array(1, 20, 25, 5, 3));
            var costSet = new Array(120000, 120000);
            item = itemSet[selectedItem];
            mats = matSet[selectedItem];
            matQty = matQtySet[selectedItem];
            cost = costSet[selectedItem];
        } else if (selectedType == 3) { //magician weapon
            var itemSet = new Array(1372032, 1382036);
            var matSet = new Array(new Array(1372010, 4000244, 4000245, 4005001, 4005003), new Array(1382035, 4000244, 4000245, 4005001, 4005003));
            var matQtySet = new Array(new Array(1, 20, 25, 6, 2), new Array(1, 20, 25, 6, 2));
            var costSet = new Array(120000, 120000);
            item = itemSet[selectedItem];
            mats = matSet[selectedItem];
            matQty = matQtySet[selectedItem];
            cost = costSet[selectedItem];
        } else if (selectedType == 4) { //thief weapon
            var itemSet = new Array(1332049, 1332050, 1472051);
            var matSet = new Array(new Array(1332051, 4000244, 4000245, 4005000, 4005002), new Array(1332052, 4000244, 4000245, 4005002, 4005003), new Array(1472053, 4000244, 4000245, 4005002, 4005003));
            var matQtySet = new Array(new Array(1, 20, 25, 5, 3), new Array(1, 20, 25, 3, 5), new Array(1, 20, 25, 2, 6));
            var costSet = new Array(120000, 120000, 120000);
            item = itemSet[selectedItem];
            mats = matSet[selectedItem];
            matQty = matQtySet[selectedItem];
            cost = costSet[selectedItem];
        } else if (selectedType == 5) { //pirate weapon
            var itemSet = new Array(1482013, 1492013);
            var matSet = new Array(new Array(1482012, 4000244, 4000245, 4005000, 4005002), new Array(1492012, 4000244, 4000245, 4005000, 4005002));
            var matQtySet = new Array(new Array(1, 20, 25, 5, 3), new Array(1, 20, 25, 3, 5));
            var costSet = new Array(120000, 120000);
            item = itemSet[selectedItem];
            mats = matSet[selectedItem];
            matQty = matQtySet[selectedItem];
            cost = costSet[selectedItem];
        }

        var prompt = "想做 #t" + item + "#? 没问题，但需要下面这些材料。#b";

        if (stimulator) {
            stimID = getStimID(item);
            prompt += "\r\n#i" + stimID + "# 1 #t" + stimID + "#";
        }

        if (mats instanceof Array) {
            for (var i = 0; i < mats.length; i++) {
                prompt += "\r\n#i" + mats[i] + "# " + matQty[i] + " #z" + mats[i] + "#";
            }
        } else {
            prompt += "\r\n#i" + mats + "# " + matQty + " #z" + mats + "#";
        }

        if (cost > 0)
            prompt += "\r\n#i4031138# " + cost + " 金币";

        cm.sendYesNo(prompt);
    } else if (status == 3 && mode == 1) {
        var complete = true;

        if (cm.getMeso() < cost) {
            cm.sendOk("糟糕...你的錢好像不夠哦...")
            cm.dispose();
            return;
        } else {
            if (mats instanceof Array) {

                for (var i = 0; complete && i < mats.length; i++)
                {
                    if (!cm.haveItem(mats[i], matQty[i]))
                    {
                        complete = false;
                    }
                }
            } else {
                if (!cm.haveItem(mats, matQty))
                {
                    complete = false;
                }
            }
        }

        if (stimulator) { //check for stimulator
            if (!cm.haveItem(stimID)) {
                complete = false;
            }
        }

        if (!complete)
            cm.sendOk("你的材料都没凑齐，我很难帮你办事啊。");
        else {
            if (mats instanceof Array) {
                for (var i = 0; i < mats.length; i++) {
                    cm.gainItem(mats[i], -matQty[i]);
                }
            } else
                cm.gainItem(mats, -matQty);

            cm.gainMeso(-cost);
            if (stimulator) { //判断是否使用制作剂
                cm.gainItem(stimID, -1);
                var deleted = Math.floor(Math.random() * 10);
                if (deleted != 0) 
				{
					if(item == 1302249)
					{
						cm.gainItem(item,风暴套装四维随机1,风暴套装四维随机2,风暴套装四维随机3,风暴套装四维随机4,风暴套装攻击力随机,风暴套装魔攻随机,1,1,1,1,1,1,1,1,0);
						cm.sendOk("制作完成了,快看看你的新武器吧.");
						cm.喇叭(2,"【制作大厅】玩家"+cm.getPlayer().getName()+"制作了一件#z"+item+"#，大家恭喜他吧");
					}
					else
					{
						cm.sendOk("1");
					}
                } 
				else 
				{
                    cm.sendOk("不幸的是，龍的精髓...抵觸你的武器。我很抱歉是我的疏失.....");
                }
            } 
			else 
			{ //正常制作走向
				if(item == 1302249 || item == 1312136|| item == 1322182|| item ==1332207|| item ==1372162|| item == 1382193|| item == 1402174|| item ==1412123|| item ==1422125|| item ==1432151|| item ==1442203|| item ==1452190|| item ==1462178|| item ==1472198|| item ==1482152)
				{
					cm.gainItem(item,风暴套装四维随机1,风暴套装四维随机2,风暴套装四维随机3,风暴套装四维随机4,0,0,风暴套装攻击力随机,风暴套装魔攻随机,1,1,1,1,1,1,0);
					cm.sendOk("制作完成了,快看看你的新武器吧.");
					cm.喇叭(2,"【制作大厅-装备制作】玩家"+cm.getPlayer().getName()+"制作了一件风暴系列装备，大家恭喜他吧");
				}
				else
				{
					cm.sendOk("1");
				}
            }
        }
        cm.dispose();
    } 
	else if (status == 100) {
        cm.sendRepairWindow();
        cm.dispose();
    }
}

function getStimID(equipID) {
    var cat = Math.floor(equipID / 10000);
    var stimBase = 4130002; //stim for 1h sword

    switch (cat) {
        case 130: //1h sword, do nothing
            break;
        case 131: //1h axe
            stimBase++;
            break;
        case 132: //1h bw
            stimBase += 2;
            break;
        case 140: //2h sword
            stimBase += 3;
            break;
        case 141: //2h axe
            stimBase += 4;
            break;
        case 142: //2h bw
            stimBase += 5;
            break;
        case 143: //spear
            stimBase += 6;
            break;
        case 144: //polearm
            stimBase += 7;
            break;
        case 137: //wand
            stimBase += 8;
            break;
        case 138: //staff
            stimBase += 9;
            break;
        case 145: //bow
            stimBase += 10;
            break;
        case 146: //xbow
            stimBase += 11;
            break;
        case 133: //dagger
            stimBase += 12;
            break;
        case 147: //claw
            stimBase += 13;
            break;
        case 148: //knuckle
            stimBase += 14;
            break;
        case 149: //gun
            stimBase += 15;
            break;
    }

    return stimBase;
}